package com.csx.governance.traffic.adm.controller;

import com.csx.governance.traffic.adm.model.common.Result;
import com.csx.governance.traffic.adm.model.dto.AttributeTypeDTO;
import com.csx.governance.traffic.adm.model.dto.OperationDTO;
import com.csx.governance.traffic.adm.model.vo.AttributeTypeVO;
import com.csx.governance.traffic.adm.model.vo.OperationVO;
import com.csx.governance.traffic.adm.service.BasicService;
import com.csx.governance.traffic.adm.util.ModelConvertUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cuisongxu
 * @date 2023/5/4 13:51
 */
@Tag(name = "基础服务控制器")
@RequestMapping("/basic")
@RestController
@AllArgsConstructor
public class BasicController {

    @Autowired
    private BasicService basicService;

    /**
     * 获取属性类型列表
     * @return 属性类型列表
     */
    @Operation(summary = "获取属性类型列表")
    @GetMapping("/types")
    public Result<List<AttributeTypeVO>> getAttributeTypes() {
        List<AttributeTypeDTO> attributeTypes = basicService.getAttributeTypes();
        List<AttributeTypeVO> res = ModelConvertUtil.convert(attributeTypes, AttributeTypeVO.class);
        return Result.success(res);
    }

    /**
     * 获取比较操作符列表
     * @return 比较操作符列表
     */
    @Operation(summary = "获取比较操作符列表")
    @GetMapping("/operations")
    public Result<List<OperationVO>> getOperations() {
        List<OperationDTO> operations = basicService.getOperations();
        List<OperationVO> res = ModelConvertUtil.convert(operations, OperationVO.class);
        return Result.success(res);
    }

}
